<template>
  <div class="link flex">
    <table border="1" class="tabledata">
      <tr>
        <td colspan="22" class="bg" style="font-size: 16px; font-weight: bold">
          水质指标分析
        </td>
      </tr>
      <tr>
        <td colspan="2" rowspan="5">净化排水</td>
        <td rowspan="2">污水处理</td>
        <td>PH</td>
        <td>COD</td>
        <td>氨氮</td>
        <td>总磷</td>
        <td>总氮</td>
        <td rowspan="2" colspan="4">排放口国控指标</td>
        <td rowspan="5" colspan="4">
          <textarea cols="40" rows="5" v-model="inputs.content1" v-if="!date.isup&&isjinghua"></textarea>
          <div v-else style="white-space: pre-line;text-align: left;">{{inputs.content1}}</div>
        </td>
      </tr>
      <tr>
        <td>6-9</td>
        <td colspan="4">(mg/L)</td>
      </tr>
      <tr>
        <td>新生化</td>
        <td><input type="number" class="dinput" v-model="inputs.phxs" v-if="!date.isup&&isjinghua"/><span v-else>{{inputs.phxs}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.codxs" v-if="!date.isup&&isjinghua"/><span v-else>{{inputs.codxs}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.adxs" v-if="!date.isup&&isjinghua"/><span v-else>{{inputs.adxs}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.zlxs" v-if="!date.isup&&isjinghua"/><span v-else>{{inputs.zlxs}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.zdxs" v-if="!date.isup&&isjinghua"/><span v-else>{{inputs.zdxs}}</span></td>
        <td colspan="4">COD：500氨氮：45总磷：10 总氮：350</td>
      </tr>
      <tr>
        <td>老生化</td>
        <td><input type="number" class="dinput" v-model="inputs.phls" v-if="!date.isup&&isjinghua"/><span v-else>{{inputs.phls}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.codls" v-if="!date.isup&&isjinghua"/><span v-else>{{inputs.codls}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.adls" v-if="!date.isup&&isjinghua"/><span v-else>{{inputs.adls}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.zlls" v-if="!date.isup&&isjinghua"/><span v-else>{{inputs.zlls}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.zdls" v-if="!date.isup&&isjinghua"/><span v-else>{{inputs.zdls}}</span></td>
        <td colspan="4">COD：150氨氮：25总磷：3 总氮：50</td>
      </tr>
      <tr>
        <td>深度处理</td>
        <td>—</td>
        <td>—</td>
        <td>—</td>
        <td>—</td>
        <td>—</td>
        <td colspan="4">—</td>
      </tr>
      <tr>
        <td colspan="2" rowspan="3">动力雨水</td>
        <td rowspan="3">雨水总排口</td>
        <td>酚</td>
        <td>悬浮物</td>
        <td>氨氮</td>
        <td>COD</td>
        <td>Cl-</td>
        <td colspan="8">雨水总排口国控指标</td>
      </tr>
      <tr>
        <td colspan="5">(mg/L)</td>
        <td colspan="8">(mg/L)</td>
      </tr>
      <tr>
        <td><input type="number" class="dinput" v-model="inputs.ysfen" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.ysfen}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.ysxfw" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.ysxfw}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.ysad" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.ysad}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.yscod" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.yscod}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.yscl" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.yscl}}</span></td>
        <td colspan="8">COD：50氨氮：5.0悬浮物：10总氮：15</td>
      </tr>
      <tr>
        <td rowspan="4" colspan="2">水源水指标</td>
        <td rowspan="2"></td>
        <td>PH</td>
        <td>硬度</td>
        <td>碱度</td>
        <td>浊度</td>
        <td>Cl-</td>
        <td>电导率</td>
        <td colspan="6" rowspan="2">进厂水源水参考指标</td>
      </tr>
      <tr>
        <td>6.5-8.5</td>
        <td colspan="4">(mg/L)</td>
        <td>μs/cm</td>
      </tr>
      <tr>
        <td>一二期</td>
        <td><input type="number" class="dinput" v-model="inputs.syph1" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.syph1}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.syyd1" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.syyd1}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.syjd1" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.syjd1}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.syzd1" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.syzd1}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.sycl1" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.sycl1}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.syddl1" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.syddl1}}</span></td>
        <td rowspan="2" colspan="6">硬度：450 碱度：350 浊度：3 Cl-：250</td>
      </tr>
      <tr>
        <td>三期</td>
        <td><input type="number" class="dinput" v-model="inputs.syph2" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.syph2}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.syyd2" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.syyd2}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.syjd2" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.syjd2}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.syzd2" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.syzd2}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.sycl2" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.sycl2}}</span></td>
        <td><input type="number" class="dinput" v-model="inputs.syddl2" v-if="!date.isup&&isdongli"/><span v-else>{{inputs.syddl2}}</span></td>
      </tr>
      <tr>
        <td colspan="22" style="text-align: left">
          <textarea cols="180" rows="1" v-model="inputs.content2" v-if="!date.isup&&isdongli"></textarea>
          <div v-else style="white-space: pre-line;text-align: left;">{{inputs.content2}}</div>
        </td>
      </tr>
    </table>
  </div>
</template>

<script lang="ts" setup name="hbzb">
import cache from "@/utils/cache";
import { getHbzb, hbzbSave, hbzbSubmit } from "@/api/report";

const uu = ref(cache.get('userInfo'))
const isjinghua = ref(false)
if(uu.value.id==1||uu.value.role_id.includes(3)||uu.value.role_id.includes(4)||uu.value.role_id.includes(8)){
  isjinghua.value = true
}
const isdongli = ref(false)
if(uu.value.id==1||uu.value.role_id.includes(3)||uu.value.role_id.includes(4)||uu.value.role_id.includes(9)){
  isdongli.value = true
}
let obj = {
  phxs:0,
  codxs:0,
  adxs:0,
  zlxs:0,
  zdxs:0,
  phls:0,
  codls:0,
  adls:0,
  zlls:0,
  zdls:0,
  ysfen:0,
  ysxfw:0,
  ysad:0,
  yscod:0,
  yscl:0,
  syph1:0,
  syyd1:0,
  syjd1:0,
  syzd1:0,
  sycl1:0,
  syddl1:0,
  syph2:0,
  syyd2:0,
  syjd2:0,
  syzd2:0,
  sycl2:0,
  syddl2:0,
  content1:'记事：其它环保设施运行正常',
  content2:'记事：'
}
// 整表 数据绑定
const inputs = ref(obj);


const save = async () => {
  let userInfo = cache.get('userInfo')
  await hbzbSave({
    inputs:inputs.value,
    aid: userInfo.id,
    aname: userInfo.name,
    date:date.date,
  })
}
const uuuu = ref(cache.get('role_name'))
// 提交方法，调用接口
const submit = async () => {
  await hbzbSubmit({
    label:uuuu.value,
    date:date.date,
  })
}

onMounted(() => {
  getData()
})

const getData = async () => {
  getHbzb(date).then((res)=>{
    if(res.length==0){
      inputs.value = obj
    }else{
      inputs.value = res
    }
  })
}
const date = defineProps(['date','isup'])
watch(date, async (n) => {
  getData()
})

defineExpose({
  save,
  submit
})
</script>
 class="bg"
<style lang="scss" scoped>
.tabledata {
  width: 100%;
  border: 1px solid #aaa;
  td {
    text-align: center;
    border: 1px solid #aaa;
    padding: 3px;
  }
  .bg{
    background: #ccc;
  }
  .dinput{
    text-align: center;
    border-radius: 5px;
    width: 80px;
    border: 1px solid #ccc;
  }
}
</style>
